import {
  feeStandardsDelete,
  feeStandardsDisable as feeStandardsDisableAPI,
  serviceStandardgetList,
  updateMobileShow,
} from '@/api/order'
import { ref } from 'vue'

export const useGetFeeStandards = () => {
  // 获取收费标准列表加载
  const getFeeStandardsLoading = ref(false)

  // 收费标准列表
  const feeStandards = ref<Array<OrderFeeStandards>>([])

  // 获取收费标准请求参数
  const getFeeStandardsParam = ref({
    page: 0,
    limit: 0,
    name: '',
  })

  // 收费标准列表总条数
  const feeStandardsTotal = ref(0)

  /**
   * 获取收费标准
   */
  const getFeeStandards = async () => {
    getFeeStandardsLoading.value = true
    const res = await serviceStandardgetList(getFeeStandardsParam.value)
    getFeeStandardsLoading.value = false
    feeStandardsTotal.value = Number(res.data.data.total)
    feeStandards.value = res.data.data.rows
  }

  return {
    feeStandards,
    feeStandardsTotal,
    getFeeStandardsParam,
    getFeeStandardsLoading,
    getFeeStandards,
  }
}

export const useFeeStandardsEnable = () => {
  // 启用加载
  const enableLoading = ref(false)

  /**
   * 收费标准批量启用
   * @param {Array<string>} feeStandardIds - 收费标准id集合
   */
  const feeStandardsEnable = async (feeStandardIds: Array<string>) => {
    enableLoading.value = true
    const res = await feeStandardsDisableAPI(feeStandardIds, false)
    enableLoading.value = false
    return res.data
  }

  return {
    enableLoading,
    feeStandardsEnable,
  }
}

export const useFeeStandardsDisable = () => {
  // 禁用加载
  const disableLoading = ref(false)

  /**
   * 收费标准批量禁用
   * @param {Array<string>} feeStandardIds - 收费标准id集合
   */
  const feeStandardsDisable = async (feeStandardIds: Array<string>) => {
    disableLoading.value = true
    const res = await feeStandardsDisableAPI(feeStandardIds, true)
    disableLoading.value = false
    return res.data
  }

  return {
    disableLoading,
    feeStandardsDisable,
  }
}

export const useFeeStandardsDelete = () => {
  // 删除加载
  const deleteLoading = ref(false)

  /**
   * 收费标准批量删除
   * @param feeStandardIds - 收费标准id集合
   */
  const feeStandardsDel = async (feeStandardIds: Array<string>) => {
    deleteLoading.value = true
    const res = await feeStandardsDelete(feeStandardIds)
    deleteLoading.value = false
    return res.data
  }

  return {
    deleteLoading,
    feeStandardsDel,
  }
}

export const useFeeStandardsMobileHide = () => {
  // 隐藏加载
  const hideLoading = ref(false)

  /**
   * 收费标准批量移动端隐藏
   * @param {Array<string>} feeStandardIds - 收费标准id集合
   */
  const feeStandardsMobileHide = async (feeStandardIds: Array<string>) => {
    hideLoading.value = true
    const res = await updateMobileShow(feeStandardIds, false)
    hideLoading.value = false
    return res.data
  }

  return {
    hideLoading,
    feeStandardsMobileHide,
  }
}

export const useFeeStandardsMobileShow = () => {
  // 显示加载
  const showLoading = ref(false)

  /**
   * 收费标准批量移动端显示
   * @param {Array<string>} feeStandardIds - 收费标准id集合
   */
  const feeStandardsMobileShow = async (feeStandardIds: Array<string>) => {
    showLoading.value = true
    const res = await updateMobileShow(feeStandardIds, true)
    showLoading.value = false
    return res.data
  }

  return {
    showLoading,
    feeStandardsMobileShow,
  }
}
